//
//  MyPicCollectionViewCell.m
//  QXShowing
//
//  Created by 王道道 on 2018/5/12.
//  Copyright © 2018年 doll_dream. All rights reserved.
//

#import "MyPicCollectionViewCell.h"

@implementation MyPicCollectionViewCell

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setUpUI];
        [self _viewLayout];
    }
    return self;
}

- (id)init {
    if (self = [super init]) {
        
    }
    return self;
}

- (void)setUpUI {
//    self.layer.shadowColor = [UIColor blackColor].CGColor;
//    self.layer.shadowOpacity = 0.1;
    
    self.contentView.backgroundColor = [UIColor clearColor];
    
    self.homeImage = [[UIImageView alloc]init];
    self.homeImage.clipsToBounds = YES;
    self.homeImage.layer.cornerRadius = 5;
    self.homeImage.image = [UIImage imageNamed:@"home-1"];
    [self.contentView addSubview:self.homeImage];
    
    self.chooseImage = [[UIImageView alloc]init];
    [self.contentView addSubview:self.chooseImage];
    
    self.btnBtn = [[UIButton alloc] init];
    [self.btnBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.btnBtn];
}

- (void)btnAction:(UIButton *)sender {
    if (self.btnBlock) {
        self.btnBlock();
    }
}

- (void)_viewLayout {
    [self.homeImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.equalTo(self.contentView);
        make.centerX.equalTo(self.contentView);
        make.centerY.equalTo(self.contentView);
    }];
    
    [self.chooseImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.offset(15);
        make.right.equalTo(self.contentView.mas_right);
        make.top.equalTo(self.contentView.mas_top);
    }];
    
    [self.btnBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.equalTo(self.contentView);
        make.centerX.equalTo(self.contentView);
        make.centerY.equalTo(self.contentView);
    }];
}

- (void)setModel:(MyPicModel *)model {
    if (![BHSettingUtil dataAndStringIsNull:model]) {
        _model = model;
        if (![BHSettingUtil dataAndStringIsNull:model.pic]) {
            [self.homeImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", BH_PicPreString, model.pic]] placeholderImage:[UIImage imageNamed:@"home-1"]];
        }
        else {
//            self.homeImage.image = [UIImage imageNamed:@"home-1"];
        }
        if (self.isChoose) {
            self.chooseImage.image = [UIImage imageNamed:@"my-7"];
        } else {
            self.chooseImage.image = [UIImage imageNamed:@"my-6"];
        }
    }
}

@end
